<body>
  <form id="form1"></form>
  <input />
</body>

<script>
  // input 可以设置 form 是个特殊
  const el = document.querySelector('input')
  el.setAttribute('form', 'form2')
  console.log(el.getAttribute('form'))
</script>
